resource "alicloud_cs_managed_kubernetes" "main" {
  name                          = var.ack_name
  version                       = var.ack_version
  timezone                      = var.ack_timezone
  resource_group_id             = var.resource_group_id
  pod_vswitch_ids               = length(var.ack_pod_vswitch_ids) > 0 ? split(",", join(",", var.ack_pod_vswitch_ids)): length(var.ack_pod_vswitch_ids) < 1 ? [] : []
  worker_vswitch_ids            = length(var.ack_worker_vswitch_ids) > 0 ? split(",", join(",", var.ack_worker_vswitch_ids)): length(var.ack_worker_vswitch_ids) < 1 ? [] : []
  node_cidr_mask                = var.ack_node_cidr_mask
  pod_cidr                      = var.ack_k8s_pod_cidr
  service_cidr                  = var.ack_k8s_service_cidr
  cluster_spec                  = "ack.pro.small" #"ack.standard" #"ack.pro.small"
  new_nat_gateway               = false
  security_group_id             = var.ack_security_group_id 
  slb_internet_enabled          = false

  control_plane_log_components  = ["apiserver", "kcm", "scheduler"]
  control_plane_log_ttl         = "30"
  control_plane_log_project     = "k8s-log-${var.ack_name}-controlplane"

  dynamic "addons" {
    for_each = var.cluster_addons
    content {
      name     = lookup(addons.value, "name", var.cluster_addons)
      config   = lookup(addons.value, "config", var.cluster_addons)
      disabled = lookup(addons.value, "disabled", var.cluster_addons)
    }
  }
  maintenance_window {
    enable            = var.ack_enable_maintenance_window
    maintenance_time  = "01:00:00Z"
    duration          = "3h"
    weekly_period     = "Monday,Friday"
  } 
  tags                = var.tags
}


